package com.dai.zhenfujin.my.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.Constants.EventConstants;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.adapter.AttentionDetailAdapter2;
import com.dai.zhenfujin.base.BaseActivity;
import com.dai.zhenfujin.bean.BlackBean;
import com.dai.zhenfujin.bean.MessageEvent;
import com.dai.zhenfujin.http.CallBack;
import com.dai.zhenfujin.http.HttpClient;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BlackActivity extends BaseActivity {

    private TextView title_textview;
    private FrameLayout fl_img;
    private RecyclerView rl_black;
    private AttentionDetailAdapter2 attentionDetailAdapter;
    private List<BlackBean.FollowListBean> black_list = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.black_activity);
        initView();
    }

    private void initView() {
        title_textview = findViewById(R.id.title_textview);
        fl_img = findViewById(R.id.fl_img);
        rl_black = findViewById(R.id.rl_black);
        title_textview.setText("黑名单");

        rl_black.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        attentionDetailAdapter = new AttentionDetailAdapter2(this, black_list);
        rl_black.setAdapter(attentionDetailAdapter);
        getBlackList();
        fl_img.setOnClickListener(v -> {
           finish();
        });
    }

    private void getBlackList() {
        Map<String, Object> params = new HashMap<>();
        Map<String, String> params2 = new HashMap<>();
        params.put("req_bd", params2);
        HttpClient.post(this, Constants.BLACKLIST, params, new CallBack<BlackBean>() {
            @Override
            public void onSuccess(BlackBean resultBean) {
                black_list.clear();
                black_list.addAll(resultBean.black_list);
                attentionDetailAdapter.notifyDataSetChanged();
                MessageEvent messageEvent = new MessageEvent();
                messageEvent.setMessageKey(EventConstants.BLOCK);
                EventBus.getDefault().post(messageEvent);
            }
        });
    }
}
